package com.mybatis.crudservice.controller;

import com.mybatis.crudservice.service.EntityService;
import com.mybatis.crudservice.tools.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ 描 述 : 实体服务controller - 支持跨域
 * @ 作 者 : 一念〃
 * @ 时 间 : 16:46 2019/6/7
 * @ 备 注 :
 */
@CrossOrigin
@RestController
@RequestMapping({"/crud/entity","/comm/entity"})
public class EntityController {

    @Autowired
    private EntityService entityService;

    //新增 - 返回受影响行数
    @PostMapping(value={"/insertReCount/{entityName}"}, consumes={"application/json", "application/x-www-form-urlencoded"})
    public ResultBean<Integer> insertReCount(@PathVariable String entityName, @RequestBody Map<String,Object> data)throws Exception{
        return new ResultBean<Integer>(entityService.insertReCount(entityName,data));
    }

    //修改 - 返回受影响行数
    @PostMapping(value={"/updateReCount/{entityName}"}, consumes={"application/json", "application/x-www-form-urlencoded"})
    public ResultBean<Integer> updateReCount(@PathVariable String entityName, @RequestBody Map<String, Object> data) throws Exception {
        return new ResultBean<Integer>(entityService.updateReCount(entityName,data));
    }

}
